package android.support.v4.app;

import android.content.Context;
import android.os.Parcelable;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import java.util.ArrayList;

public final class FragmentTabHost extends TabHost
  implements TabHost.OnTabChangeListener
{
  private final ArrayList a;
  private Context b;
  private l c;
  private int d;
  private TabHost.OnTabChangeListener e;
  private s f;
  private boolean g;

  private t a(String paramString, t paramt)
  {
    Object localObject = null;
    int i = 0;
    if (i < this.a.size())
    {
      s locals = (s)this.a.get(i);
      if (!(s.b(locals).equals(paramString)))
        break label214;
      localObject = locals;
    }
    while (true)
    {
      while (true)
        i += 1;
      if (localObject == null)
        throw new IllegalStateException("No tab known for tag " + paramString);
      paramString = paramt;
      if (this.f != localObject)
      {
        paramString = paramt;
        if (paramt == null)
          paramString = this.c.a();
        if ((this.f != null) && (s.a(this.f) != null))
          paramString.a(s.a(this.f));
        if (localObject != null)
        {
          if (s.a(localObject) != null)
            break label201;
          s.a(localObject, Fragment.a(this.b, s.c(localObject).getName(), s.d(localObject)));
          paramString.a(this.d, s.a(localObject), s.b(localObject));
        }
      }
      while (true)
      {
        this.f = localObject;
        return paramString;
        label201: label214: paramString.b(s.a(localObject));
      }
    }
  }

  protected final void onAttachedToWindow()
  {
    super.onAttachedToWindow();
    String str = getCurrentTabTag();
    Object localObject1 = null;
    int i = 0;
    if (i < this.a.size())
    {
      s locals = (s)this.a.get(i);
      s.a(locals, this.c.a(s.b(locals)));
      Object localObject2 = localObject1;
      if (s.a(locals) != null)
      {
        localObject2 = localObject1;
        if (!(s.a(locals).A))
        {
          if (!(s.b(locals).equals(str)))
            break label109;
          this.f = locals;
          localObject2 = localObject1;
        }
      }
      while (true)
      {
        while (true)
        {
          i += 1;
          localObject1 = localObject2;
        }
        label109: localObject2 = localObject1;
        if (localObject1 == null)
          localObject2 = this.c.a();
        ((t)localObject2).a(s.a(locals));
      }
    }
    this.g = true;
    localObject1 = a(str, (t)localObject1);
    if (localObject1 == null)
      return;
    ((t)localObject1).a();
    this.c.b();
  }

  protected final void onDetachedFromWindow()
  {
    super.onDetachedFromWindow();
    this.g = false;
  }

  protected final void onRestoreInstanceState(Parcelable paramParcelable)
  {
    paramParcelable = (SavedState)paramParcelable;
    super.onRestoreInstanceState(paramParcelable.getSuperState());
    setCurrentTabByTag(paramParcelable.a);
  }

  protected final Parcelable onSaveInstanceState()
  {
    SavedState localSavedState = new SavedState(super.onSaveInstanceState());
    localSavedState.a = getCurrentTabTag();
    return localSavedState;
  }

  public final void onTabChanged(String paramString)
  {
    if (this.g)
    {
      t localt = a(paramString, null);
      if (localt != null)
        localt.a();
    }
    if (this.e == null)
      return;
    this.e.onTabChanged(paramString);
  }

  public final void setOnTabChangedListener(TabHost.OnTabChangeListener paramOnTabChangeListener)
  {
    this.e = paramOnTabChangeListener;
  }

  public final void setup()
  {
    throw new IllegalStateException("Must call setup() that takes a Context and FragmentManager");
  }
}